﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcs.Web.demandplaninfo
{
    public partial class Modify : Web.Admin.BasePage
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int dpid = (Convert.ToInt32(Request.Params["id"]));
                    lcs.BLL.pmtypeinfo pmbll = new BLL.pmtypeinfo();
                    DataSet ds = pmbll.GetList("");
                    ddlptype.DataSource = ds;
                    ddlptype.DataTextField = "pmtype";
                    ddlptype.DataValueField = "pmid";
                    ddlptype.DataBind();
                    ShowInfo(dpid);
                }
                Page.DataBind();
            }
        }

        private void ShowInfo(int dpid)
        {
            lcs.BLL.demandplaninfo bll = new lcs.BLL.demandplaninfo();
            lcs.Model.demandplaninfo model = bll.GetModel(dpid);
            this.lbldpid.Text = model.dpid.ToString();
            this.txtpbh.Text = model.pbh;
            hfpid.Value = model.proid;
            ddlptype.SelectedValue = model.ptype.ToString();

        }

        public void btnSave_Click(object sender, EventArgs e)
        {
            if (IsLogin())
            {
                string strErr = "";
                string proid = hfpid.Value;
                if (this.txtpbh.Text.Trim().Length == 0)
                {
                    strErr += "计划编号不能为空！\\n";
                }
                if (proid == "")
                {
                    strErr += "项目不能为空！\\n";
                }
                if (strErr != "")
                {
                    MessageBox.Show(this, strErr);
                    return;
                }
                int dpid = int.Parse(this.lbldpid.Text);
                string pbh = this.txtpbh.Text;
                int uid = getid();
                string dep = getdep();
                int ptype = int.Parse(this.ddlptype.SelectedValue.ToString());
                lcs.Model.demandplaninfo model = new lcs.Model.demandplaninfo();
                model.dpid = dpid;
                model.pbh = pbh;
                model.uid = uid;
                model.ptype = ptype;
                model.proid = proid;      
                lcs.BLL.demandplaninfo bll = new lcs.BLL.demandplaninfo();
                bll.Update(model);
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "List.aspx");
            }
            else
            {
                Response.Redirect("~/jump.html");
            }


        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("List.aspx");
        }
    }
}
